from rest_framework import serializers
from apps.HttpTestcase.models import Testsuite
from apps.HttpTestcase.serializers.project import ProjectModuleSerializer
# from HttpTestcase.models.testsuite2testcase import Testsuite2Testcase
from apps.HttpTestcase.models import Testcases


class TestsuiteNamesSerializer(serializers.ModelSerializer):
    class Meta:
        model = Testsuite
        fields = ('id', 'name')


class TestSuiteSerializer(serializers.ModelSerializer):
    project = ProjectModuleSerializer()
    testcases = serializers.SerializerMethodField()
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
    update_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)

    # Testsuite2Testcase = Testsuite2TestcaseModuleSerializer()

    def get_testcases(self, obj):
        result = obj.testcases.values('id', 'name', 'is_delete')
        return result

    class Meta:
        model = Testsuite
        fields = '__all__'


class TestCreatsuiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = Testsuite
        exclude = ('status', 'testcases')


class TestSuiteModuleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Testsuite
        fields = ('id', 'name', 'is_delete')
